/**
 * @description: 下载文件
 * @param stream 文件源，string or buffer
 * @param name 文件名称
 * @param mimeType type josn
 * @return new tree data  纯函数
 */
const downFile = (stream, name, mimeType = "text/plain;charset=utf-8") => {
    // 创建 Blob 对象
    let blob;
    if (typeof stream === "string") {
        blob = new Blob([stream], { type: mimeType });
    }
    else {
        blob = new Blob([stream], { type: mimeType });
    }
    // 创建下载链接并触发下载
    const a = document.createElement("a");
    a.href = URL.createObjectURL(blob);
    a.download = name;
    a.style.display = "none";
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(a);
    // 清理创建的 URL 对象
    URL.revokeObjectURL(a.href);
};

export { downFile };
